# 1.导入依赖
'''
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver

# Chrome配置
option = webdriver.ChromeOptions()
option.add_experimental_option("detach", True)
# 实例化driver驱动
driver = webdriver.Chrome(options=option)
driver.implicitly_wait(15)
# 打开指定网址
driver.get("http://www.bjhospital.net/")
# 浏览器窗口最大化
driver.maximize_window()

# 输入查找元素的方式(通过xpash搜索）：
driver.find_element(By.XPATH, "//*[@id='header']/div/div/div/form/input[2]").send_keys("骨科")

# send_keys输入内容的意思bn fl iconfont   t//*[@id="header"]/div/div/div/form/button
driver.find_element(By.XPATH, "//*[@id='header']/div/div/div/form/button").click()

driver.find_element(By.PARTIAL_LINK_TEXT, "毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开").click()

win = driver.window_handles  # 获取全部句柄
driver.switch_to.window(win[-1])
# 断言
text_result = driver.find_element(By.XPATH, "/html/body/div[3]/div/div/article/h1").text

print(text_result)

assert text_result == "毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开"
'''

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver

option = webdriver.ChromeOptions()  # todo：chrome浏览器配置项
option.add_experimental_option("detach", True)  # todo：浏览器不会自动关闭
driver = webdriver.Chrome(options=option)


class SearchName:
    def __init__(self, driver):
        self.driver = driver
        # 打开全局url
        self.driver.get("http://www.bjhospital.net/")
        self.driver.maximize_window()

    def inpt_up(self, text: str):
        WebDriverWait(self.driver, 10, 0.5).until(
            EC.presence_of_element_located((By.XPATH, "//*[@id='header']/div/div/div/form/input[2]"))).send_keys(text)
    def dianji(self):
            WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH, "//*[@id='header']/div/div/div/form/button"))).click()
    def a(self):
        WebDriverWait(self.driver, 10, 0.5).until(
            EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开"))).click()

    def c(self):
        win = self.driver.window_handles  # 获取全部句柄
        self.driver.switch_to.window(win[-1])
        text_result = self.driver.find_element(By.XPATH, "/html/body/div[3]/div/div/article/h1").text
        print(text_result)
        assert text_result == "毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开"

    def exit_l(self):
        self.driver.quit()
if __name__ == '__main__':
    bro = SearchName(driver)
    bro.inpt_up("骨科")
    bro.dianji()
    bro.a()
    bro.c()
    print(driver.title)
    bro.exit_l()
